package com.boruan.qq.zxgylibrary.utils;

import android.util.Log;

/**
 * Created by 崔琦 on 2019/7/24.
 * des: 重复点击处理
 */

public class CButtonUtils {

    private static long lastClickTime = 0;
    private static long DIFF = 1000;
    private static int lastButtonId = -1;
    private static long DIFFive = 5000;


    /**
     * 判断两次点击的间隔，如果小于1000，则认为是多次无效点击
     */
    public static boolean isFastDoubleClick(int buttonId) {
        return isFastDoubleClick(buttonId, DIFF);
    }

    /**
     * 判断两次点击的间隔，如果小于diff，则认为是多次无效点击
     */
    public static boolean isFastDoubleClick(int buttonId, long diff) {
        long time = System.currentTimeMillis();
        long timeD = time - lastClickTime;
        if (lastButtonId == buttonId && lastClickTime > 0 && timeD < diff) {
            Log.i("isFastDoubleClick", "短时间内按钮多次触发");
            return true;
        }
        lastClickTime = time;
        lastButtonId = buttonId;
        return false;
    }

    /**
     * 判断两次点击的间隔，如果小于5000，则认为是多次无效点击
     */
    public static boolean isFastFiveSecond(int buttonId) {
        return isFastDoubleClick(buttonId, DIFFive);
    }

}
